//
//  NRLSVMTSubjectViewController+Request.m
//  NaRiLSVMT
//
//  Created by jmsre on 14-8-25.
//  Copyright (c) 2014年 helloyouth.org. All rights reserved.
//

#import "NRLSVMTSubjectViewController+Request.h"
#import "MBProgressController.h"
#import "Network_Operation.h"
#import "AllNodesInScrollView.h"
#import "TopLargerScreenView.h"
#import "RootScreenView.h"
#import "TopScreenView.h"


@implementation NRLSVMTSubjectViewController (Request)


//获取所有 流程
-(void)NRLSMTGetFlowForPad
{
  //  [[MBProgressController sharedInstance] showWithText:@"正在努力加载..."];
    WeakSelf;
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        NSString *getFlowStr = [Network_API Network_API_GetFlowForPad];
        
        AFHTTPClient *httpClient = [Network_Operation httpClientWithUrl:getFlowStr];
        NSString    *str = [NSString stringWithFormat:@"[{\"classname\":%@,\"methodname\":%@,\"parameterClasss\":[{\"parametername\":%@,\"parametervalue\":\"%@\",\"valuetype\":%@}]}]",@"\"iControlSolutionService\"",@"\"getFlowForPad\"",@"\"userId\"",subjectId,@"\"java.lang.String\""];
        [httpClient postPath:getFlowStr
                  parameters:@{@"jsonstr":str,
                               @"callback":@""
                               }
                     success:^(AFHTTPRequestOperation *operation, id responseObject) {
                         if([responseObject isKindOfClass:[NSString class]])
                         {
                             NSString *resStr = [NSString stringWithString:responseObject];
                             if(!([resStr rangeOfString:@"id"].location == NSNotFound))
                             {
                                 NSLog(@"getFlowForPad Success");
                                 
                                 
                                 wself.sendData = [NSMutableArray arrayWithArray:[Common jsontoArr:resStr]];
                                 if(allFlowDataArr == nil)
                                 {
                                     allFlowDataArr = [NSMutableArray array];
                                 }
                                 else
                                 {
                                     [allFlowDataArr removeAllObjects];
                                 }
                                 
                                 for(NSDictionary *dic in wself.sendData)
                                 {
                                     //每个流程的数据源初始化，如还需要额外的参数，在这里添加
                                     /*****************
                                      * havePlayNodeIndex:已经播放到第几个节点
                                      * haveChooseNodeIndex:已经查看到几个节点
                                      * screenNo:节点中的第几个屏幕
                                      * pauseFlag:播放暂停标识:0,初始值;1:暂停;2:播放使用权(是否允许“循环或者单次”);
                                      * isNodePagePlay://是否是在节点界面播放。是：YES.否：NO.
                                      * isCanActionOtherButton://禁止快速点击播放按钮
                                      ********/
                                     NSMutableArray *arr = [NSMutableArray array];//节点按钮数组buttonArray
                                     NSMutableArray *thumbArr = [NSMutableArray array];//节点缩略图Array
                                     UIImageView    *shadowImageView = [[UIImageView alloc]init];//投屏时显示的黄色边框
                                     NSMutableArray *receiveFlowDetailData = [NSMutableArray array];
                                     NSMutableArray *receiveFlowNodeData = [NSMutableArray array];
                                     //某个流程详细信息上部view
                                     TopLargerScreenView *topLargerScr = [[TopLargerScreenView alloc] initWithFrame:CGRectMake(0, 40, Screen_Width-20, 430-40)];
                                     //某个流程详细信息下部view
                                     AllNodesInScrollView *bottomSmaPic = [[AllNodesInScrollView alloc] initWithFrame:CGRectMake(0, 0, (Screen_Width-20), 400)];
                                     //某个节点缩略图详细信息下部view
                                     RootScreenView *rootScreenView = [[RootScreenView alloc] initWithFrame:CGRectMake(10, 114,(Screen_Width-20), 430-40)];
                                     //某个节点缩略图详细信息上部按钮
                                     TopScreenView *topScreenView = [[TopScreenView alloc] initWithFrame:CGRectMake(0, 0,100, 40)];
                                     //流程中的第一个节点
                                     NSMutableArray *firstNodeData = [NSMutableArray array];
                                     NSMutableArray *allNodeDataInFlow = [NSMutableArray array];
                                     NSDictionary *baseDic = @{@"playFlag": @(0),@"nodeButtonArr":arr,@"nodeThumbnailArr":thumbArr,@"havePlayNodeIndex":@(0),@"haveChooseNodeIndex":@(0),@"screenNo":@(0),@"intervalTime":@(5),@"shadowImageView":shadowImageView,@"topLargerScr":topLargerScr,@"bottomSmaPic":bottomSmaPic,@"rootScreenView":rootScreenView,@"topScreenView":topScreenView,@"receiveFlowDetailData":receiveFlowDetailData,@"receiveFlowNodeData":receiveFlowNodeData,@"firstNodeData":firstNodeData,@"allNodeDataInFlow":allNodeDataInFlow,@"pauseFlag":@(0),@"isNodePagePlay":@(0),@"isCanActionOtherButton":@(0)};
                                     NSMutableDictionary *dataDic = [NSMutableDictionary dictionaryWithDictionary:baseDic];
                                     NSDictionary   *initDic = @{[dic objectForKey:@"id"]: dataDic};
                                     
                                     NSMutableDictionary *flowData = [NSMutableDictionary dictionaryWithDictionary:initDic];
                                     
                                     [allFlowDataArr addObject:flowData];
                                 }
                                 
                                 wself.secondViewController = [[FlowControlViewController alloc] initWithNibName:@"FlowControlViewController" bundle:nil Date:self.sendData];
                                 wself.secondViewController.view.frame = CGRectMake(Screen_Width,0,Screen_Width,Screen_Height);
                                 [wself.scrollView addSubview:wself.secondViewController.view];
                             }
                             else
                             {
                                 dispatch_async(dispatch_get_main_queue(), ^{
                                    // self.navigationController.navigationBar.hidden = YES;
                                     wself.secondViewController = [[FlowControlViewController alloc] initWithNibName:@"FlowControlViewController" bundle:nil Date:self.sendData];
                                     wself.secondViewController.view.frame = CGRectMake(Screen_Width,0,Screen_Width,Screen_Height);
                                     [wself.scrollView addSubview:wself.secondViewController.view];
                                     [[MBProgressController sharedInstance] hide];
                                     [[MBProgressController sharedInstance] showTipsOnlyText:@"查询流程失败" AndDelay:1.5];
                                 });
                                 NSLog(@"直接返回");
                             }
                         }
                         else {
                             dispatch_async(dispatch_get_main_queue(), ^{
                               //  self.navigationController.navigationBar.hidden = YES;
                                 [[MBProgressController sharedInstance] hide];
                                 [[MBProgressController sharedInstance] showTipsOnlyText:@"查询流程失败"
                                                                                AndDelay:1.5];
                             });
                             NSLog(@"直接返回");
                         }
                     } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                         dispatch_async(dispatch_get_main_queue(), ^{
                          //   self.navigationController.navigationBar.hidden = YES;
                             [[MBProgressController sharedInstance] hide];
                             [[MBProgressController sharedInstance] showTipsOnlyText:@"查询流程失败"
                                                                            AndDelay:1.5];
                         });
                     }];
    });
   // [[MBProgressController sharedInstance] hide];
}


@end
